package com.server.server_a10.controller.smog;

import com.server.server_a10.entity.Inform;
import com.server.server_a10.entity.smog.Smog;
import com.server.server_a10.mapper.SmogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class SmogHandle {
    @Autowired
    SmogMapper smogMapper;
    @PostMapping(value = "/getSmogInfByRoomId")
    public Inform getSmogInfByRoomId(@RequestBody Map<String,Object> request){
        Inform inform = new Inform();
        int id = (int)request.get("id");
        List<Smog> smogs = smogMapper.getSmogInfByRoomId(id);
        if (smogs.isEmpty()){
            inform.setCode(100);
            inform.setMsg("当前房间没有smog传感器");
        }else {
            inform.setCode(200);
            inform.setData(smogs);
            inform.setMsg("smog信息加载成功");
        }

        return inform;
    }
}
